<?php

// +---------------------------------------------+
// |     Copyright  2010 - 2018 InterPhoto       |
// |     http://www.weentech.com                 |
// |     This file may not be redistributed.     |
// +---------------------------------------------+

if(!defined('INTERPHOTO')) die('File not found!');


// ######################################################

include(BASEPATH . 'includes/InterPhoto.GlobalFunctions.php');


// ############################### PRINT HEADER ################################

function PrintHeader($pagetitle)
{
	echo '<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
	<link rel="stylesheet" type="text/css" href="'.TEMPLATEPATH.'style.css" />
	<script type="text/javascript" src="javascript/Admin.Functions.js"></script>
	<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
	<!--
		if(top.location == self.location)
		{
			top.location.replace("index.php");
		}
	-->
	</SCRIPT>
	</head>
	<body>
	<table width=100%" border="0" cellpadding="0" cellspacing="0" class="header">
	<tr>
	<td align="center"><p class="pagetitle">'.$pagetitle.'</p></td>
	</tr>
	</table>
	<br /><br />';
}


// ############################### PRINT SUBMIT ################################

function PrintSubmit($name, $value)
{
	echo '<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
	<td align="center">
	<input type="hidden" name="'.$name.'" value="'.$value.'" />
	<input type="submit" value="'.$value.'" />
	</td>
	</tr>
	</table>';
}

// ############################### PRINT SECTION ###############################

function PrintSection($sectionname)
{
	echo '<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
	<td width="15" height="30"><img src="'.TEMPLATEPATH.'images/section/section_top_left.gif" /></td>
	<td width="100%" background="'.TEMPLATEPATH.'images/section/section_top_bg.gif" valign="bottom" align="center">
	<div style="font-family:verdana;font-size:10pt;color:#5D729B"><b>'.$sectionname.'</b></div>
	</td>
	<td width="15" height="30"><img src="'.TEMPLATEPATH.'images/section/section_top_right.gif" /></td>
	</tr>
	<tr>
	<td width="15" height="4"><img src="'.TEMPLATEPATH.'images/section/section_top_left2.gif" /></td>
	<td background="'.TEMPLATEPATH.'images/section/section_top_bg2.gif"></td>
	<td width="15" height="4"><img src="'.TEMPLATEPATH.'images/section/section_top_right2.gif" /></td>
	</tr>
	<tr>
	<td colspan="3">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
	<td width="7" background="'.TEMPLATEPATH.'images/section/section_middle_left.gif"></td>
	<td>';
}


// ################################ END SECTION ################################

function EndSection()
{
	echo '</td>
	<td width="7" background="'.TEMPLATEPATH.'images/section/section_middle_right.gif"></td>
	</tr>
	</table>
	</td>
	</tr>
	</table>
	<br /><br />';
}


// ############################### PAGE REDIRECT ###############################

function PrintRedirect($gotopage, $timeout = 0)
{

	$gotopage = str_replace('&amp;', '&', $gotopage);

	PrintSection('完成更新!');
	echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">
	<tr>
	<td class="tdrow1"  colspan="2">跳转中 ...</td>
	</tr>
	<tr>
	<td class="tdrow2" width="70%" ><a href="'.$gotopage.'" onclick="javascript:clearTimeout(timerID);">
	<font class=ohblueb><u>数据更新已完成! 如果网页没有跳转，请点击这里.</u></font></a></font>
	</td>
	</tr>
	</table>';

	echo '<script type="text/javascript">';
	if($timeout == 0){
		echo 'window.location="'.$gotopage.'"';
	}else{
		echo 'timeout = '.($timeout*10).';
		function Refresh()
		{
			timerID = setTimeout("Refresh();", 100);
			if (timeout > 0)
			{
				timeout -= 1;
			}else{
				clearTimeout(timerID);
				window.location="'.$gotopage.'";
			}
		}
		Refresh();';
	}
	echo '</script>';

	EndSection();
	PrintFooter();

	exit();
}

// ############################### PRINT FOOTER ################################

function PrintFooter()
{
	echo '<br /><br /><br /><br />
	<table width="48%" border="0" cellpadding="0" cellspacing="0" align="center">
	<tr><td align="center"><p class="copyright">' . APP_NAME .' '. APP_VERSION . ' '.base64_decode('5Zu+54mH572R56uZ566h55CG57O757uf').' &copy;'.date("Y").' '.base64_decode('6Ze75rOw572R57uc').'</p><br><a href="http://www.weentech.com" target="_blank"><img src="'.TEMPLATEPATH.'images/wenlo.gif" title="'.base64_decode('6Ze75rOw572R57uc').'" /></a><br></td></tr>
	</table>
	</body>
	</html>';
}

// ############################### PRINT ERROR #################################

function PrintErrors($errors, $errortitle = '运行错误')
{
	echo '<table width="100%" border="0" cellpadding="5" cellspacing="6">
	<tr><td style="border: 1px solid #FF0000; font-size: 12px;" bgcolor="#FFE1E1"><u>' . $errortitle . '</u><br /><br />系统运行过程中发现如下错误:<br />';

	if(is_array($errors))
	{
		for($i = 0; $i < count($errors); $i++)
			echo '<b>' . ($i + 1) . ') ' . $errors[$i] . '</b><br />';
	}else {
		echo '<b>1) ' . $errors . '</b><br />';
	}

	echo '</td></tr></table>';
}


// ########################### Show Error Message ##############################

function Errmsg($string) {
	echo "<script> alert('$string');  history.back(); </script> "; exit();
}


// ########################### Check Access ##############################

function CheckAccess($Access = 'noAccess') {
	global $userinfo;

	if (ForceInt($userinfo[''.$Access]) <> 1) {
		if (ForceInt($userinfo['manage'])){
			header("Location: admin.noaccess.php");
			exit;
		}else{
			AdminLoginOut();
		}
	}
}

// ########################### ADMIN PAGELIST ##############################

function GetPageList($FileName, $PageCount, $CurrentPage = 1, $PagesToDisplay = 10, $PN01 = '', $PNV01 = '', $PN02 = '', $PNV02 = '', $PN03 = '', $PNV03 = '', $PN04 = '', $PNV04 = '', $PN05 = '', $PNV05 = '') {

	$PreviousText =  '&nbsp;&#60;&#60;&nbsp;';
	$NextText = '&nbsp;&#62;&#62;&nbsp;';

	$Params = '';
	$Params .= Iif($PN01 AND $PNV01, '&'.$PN01.'='.$PNV01);
	$Params .= Iif($PN02 AND $PNV02, '&'.$PN02.'='.$PNV02);
	$Params .= Iif($PN03 AND $PNV03, '&'.$PN03.'='.$PNV03);
	$Params .= Iif($PN04 AND $PNV04, '&'.$PN04.'='.$PNV04);
	$Params .= Iif($PN05 AND $PNV05, '&'.$PN05.'='.$PNV05);

	$iPagesToDisplay = $PagesToDisplay - 2;      
	if ($iPagesToDisplay <= 8) $iPagesToDisplay = 8;

	$MidPoint = ($iPagesToDisplay / 2);

	$FirstPage = $CurrentPage - $MidPoint;
	if ($FirstPage < 1) $FirstPage = 1;

	$LastPage = $FirstPage + ($iPagesToDisplay - 1);

	if ($LastPage > $PageCount) {
		$LastPage = $PageCount;
		$FirstPage = $PageCount - $iPagesToDisplay;
		if ($FirstPage < 1) $FirstPage = 1;
	}

	$sReturn = '<div class="PageListDiv"><ol class="PageList">';
	$Loop = 0;
	$iTmpPage = 0;

	if ($PageCount > 1) {
		if ($CurrentPage > 1) {
			$iTmpPage = $CurrentPage - 1;
			$sReturn .= '<li><a href="' . $FileName . '?page=' . $iTmpPage . $Params . '" class="PagePrev"  onfocus="this.blur()">'.$PreviousText.'</a></li>';
		} else {
			$sReturn .= '<li><span class="NoPagePrev">'.$PreviousText.'</span></li>';
		}

		if ($FirstPage > 2) {
			$sReturn .= '&nbsp;<li><a href="' . $FileName . '?page=1' . $Params . '" onfocus="this.blur()">1</a></li>&nbsp;<li>...</li>';
		} elseif ($FirstPage == 2) {
			$sReturn .= '&nbsp;<li><a href="' . $FileName . '?page=1' . $Params . '" onfocus="this.blur()">1</a></li>';
		}

		$Loop = 0;

		for ($Loop = 1; $Loop <= $PageCount; $Loop++) {
			if (($Loop >= $FirstPage) && ($Loop <= $LastPage)) {
				if ($Loop == $CurrentPage) {
					$sReturn .= '&nbsp;<li><span class="CurrentPage">'.$Loop.'</span></li>';
				} else {
					$sReturn .= '&nbsp;<li><a href="' . $FileName . '?page=' . $Loop . $Params . '" onfocus="this.blur()">'.$Loop.'</a></li>';
				}
			}
		}

		if ($CurrentPage < ($PageCount - $MidPoint) && $PageCount > $PagesToDisplay - 1) {
			$sReturn .= '&nbsp;<li>...</li>&nbsp;<li><a href="' . $FileName . '?page=' . $PageCount . $Params . '" onfocus="this.blur()">'.$PageCount.'</a></li>';
		} else if ($CurrentPage == ($PageCount - $MidPoint) && ($PageCount > $PagesToDisplay)) {
			$sReturn .= '&nbsp;<li><a href="' . $FileName . '?page=' . $PageCount . $Params . '" onfocus="this.blur()">'.$PageCount.'</a></li>';
		}

		if ($CurrentPage != $PageCount) {
			$iTmpPage = $CurrentPage + 1;
			$sReturn .= '&nbsp;<li><a href="' . $FileName . '?page=' . $iTmpPage . $Params . '" class="PageNext" onfocus="this.blur()">'.$NextText.'</a></li>';
		} else {
			$sReturn .= '&nbsp;<li><span class="NoPageNext">'.$NextText.'</span></li>';
		}
	} else {
		$sReturn .= '<li>&nbsp;</li>';
	}

	$sReturn .= '</ol></div>';

	return  $sReturn;
}

// ################################ NewObject ##############################

function NewObject($ClassName, $Param1 = '', $Param2 = '', $Param3 = '') {
	if (!class_exists($ClassName)) {

		$File = BASEPATH . 'includes/Class.' . $ClassName . '.php';

		if (file_exists($File)) {
			include($File);
		}
	}

	return new $ClassName($Param1, $Param2, $Param3);
}



?>